import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login'
import layout from '@/components/layout'
import home from '@/components/home'
import area from '@/components/sys/area'
import dict from '@/components/sys/dict'
import menu from '@/components/sys/menu'
import role from '@/components/sys/role'
import user from '@/components/sys/user'
import userinfo from '@/components/sys/userinfo'
import logs from '@/components/sys/logs'
import gz from '@/components/comm/gz'
//填报设置
import fillset from '@/components/fillset/set.vue'
import fillcreat from '@/components/fillset/creat'
//填报
import prosurvey from '@/components/fillin/prosurvey'
import exportss from '@/components/fillin/export'
import prosecution from '@/components/fillin/prosecution'
import promotion from '@/components/fillin/promotion'
import proseason from '@/components/fillin/proseason'
//审核
import rprosurvey from '@/components/review/prosurvey'
import rexportss from '@/components/review/export'
import rprosecution from '@/components/review/prosecution'
import rpromotion from '@/components/review/promotion'
import rproseason from '@/components/review/proseason'
//统计
import sprosurvey from '@/components/statistics/prosurvey'
import sexportss from '@/components/statistics/export'
import sprosecution from '@/components/statistics/prosecution'
import spromotion from '@/components/statistics/promotion'
import sproseason from '@/components/statistics/proseason'

import store from '../store/store'
import vueext from '../extended/vueext'

import axios from '../config'//默认http请求配置
//引入vue扩展方法
Vue.use(vueext)
Vue.use(Router)

const routes = [
  { path: '/', name: '登录', component: login },
  {
    path: '/layout', name: '框架', component: layout, children: [
      { path: '/home', name: '首页', meta: { icon: "ios-home-outline" }, component: home },
      { path: '/sys/area', name: '行政区划管理', meta: { icon: "map" }, component: area },
      { path: '/sys/dict', name: '数据字典', meta: { icon: "gear-b" }, component: dict },
      { path: '/sys/menu', name: '菜单管理', meta: { icon: "ios-list-outline" }, component: menu },
      { path: '/sys/role', name: '角色管理', meta: { icon: "briefcase" }, component: role },
      { path: '/sys/user', name: '用户管理', meta: { icon: "person-stalker" }, component: user },
      { path: '/sys/userinfo', name: '个人信息修改', meta: { icon: "person-stalker" }, component: userinfo },
      { path: '/sys/logs', name: '日志管理', meta: { icon: "clipboard" }, component: logs },
      { path: '/fillset/set', name: '填报设置', meta: { icon: "settings" }, component: fillset },
      { path: '/fillset/creat', name: '填报生成', meta: { icon: "social-buffer" }, component: fillcreat },
      { path: '/county/prosurvey', name: '（二）主要水果生产情况年度面积产量统计表', meta: { icon: "social-buffer" }, component: prosurvey },
      { path: '/county/export', name: '（三）外销统计表', meta: { icon: "social-buffer" }, component: exportss },
      { path: '/county/prosecution', name: '（四）生产经营实体情况表', meta: { icon: "social-buffer" }, component: prosecution },
      { path: '/county/promotion', name: '（五）技术推广机构及人员表', meta: { icon: "social-buffer" }, component: promotion },
      { path: '/city/promotion', name: '州(市)技术推广机构及人员表', meta: { icon: "social-buffer" }, component: promotion },
      { path: '/review/prosurvey', name: '（二）主要水果生产情况年度面积产量统计表审核', meta: { icon: "social-buffer" }, component: rprosurvey },
      { path: '/review/export', name: '（三）外销统计表审核', meta: { icon: "social-buffer" }, component: rexportss },
      { path: '/review/prosecution', name: '（四）生产经营实体情况表审核', meta: { icon: "social-buffer" }, component: rprosecution },
      { path: '/review/promotion', name: '（五）技术推广机构及人员表审核', meta: { icon: "social-buffer" }, component: rpromotion },
      { path: '/county/proseason', name: '（一）主要水果生产情况季度表', meta: { icon: "social-buffer" }, component: proseason },
      { path: '/review/proseason', name: '（一）主要水果生产情况季度表审核', meta: { icon: "social-buffer" }, component: rproseason },
      { path: '/statis/prosurvey', name: '（二）主要水果生产情况年度面积产量汇总', meta: { icon: "social-buffer" }, component: sprosurvey },
      { path: '/statis/export', name: '（三）外销统计汇总', meta: { icon: "social-buffer" }, component: sexportss },
      { path: '/statis/prosecution', name: '（四）生产经营实体情况汇总', meta: { icon: "social-buffer" }, component: sprosecution },
      { path: '/statis/promotion', name: '（五）技术推广机构及人员汇总', meta: { icon: "social-buffer" }, component: spromotion },      
      { path: '/statis/proseason', name: '（一）主要水果生产情况季度汇总', meta: { icon: "social-buffer" }, component: sproseason },
    ]
  }
];
let router = new Router({
  routes
});

// 全局 before 钩子: 进入下一个路由前， 修改 Vuex 中的 breadcrumb 内容
router.beforeEach((to, from, next) => {
  var user = Vue.prototype.GetlocaStorage("fruuserinfo");
  var userActions=Vue.prototype.GetlocaStorage("fruuseractionlist");
  if (to.name !== '登录') {
    if (user !== null) {
      if (to.path !== '/home') {
        //面包削数据更新
        var BreadcrumbItem = new Object();
        BreadcrumbItem.RouterName = to.name;
        BreadcrumbItem.RouterUrl = to.path;
        BreadcrumbItem.RouterIcon = to.meta.icon;
        store.dispatch('updateBreadcrumb', BreadcrumbItem);
        //用户操作按钮权限列表数据更新
        var actionInfo=new Object();
        actionInfo.path=to.path;
        actionInfo.account=user.Account;
        actionInfo.AreaCode = user.AreaCode;
        actionInfo.list=userActions;
        store.dispatch('setActionList', actionInfo);
      } else {
        store.dispatch('desBreadcrumb');
      }
      next();
    } else {
      next({
        path: '/'
      })
    }
  } else {
    next();
  }
})
export default router;